{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "from bokeh.plotting import figure, show, output_notebook"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "X = np.array([[0, 1, 1], [1, 0, 1], [1, 1, 1], [-1, 1, 1], [1, -1, 1]])\n",
    "Y = np.array([1, 1, 1, 0, 0])\n",
    "W = np.zeros(3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## algorithm"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "def perceptron(x, w):\n",
    "    return (x @ w >= 0).astype(int)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "def train(x, y, w):\n",
    "    for i in range(len(x)):\n",
    "        # evaluate perceptron\n",
    "        h = perceptron(x[i, :], w)\n",
    "        \n",
    "        # misclassification\n",
    "        if h != y[i]:\n",
    "            # positive sample\n",
    "            if y[i] == 1: \n",
    "                w += x[i, :]\n",
    "            # negative sample\n",
    "            else:         \n",
    "                w -= x[i, :]\n",
    "    \n",
    "    # evaluate\n",
    "    return perceptron(x, w)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## training"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "y= [1 1 1 0 0]\n",
      "w= [ 0.  0. -2.] acc= 0.4\n",
      "w= [ 1.  1. -2.] acc= 0.6\n",
      "w= [ 2.  1. -2.] acc= 0.8\n",
      "w= [ 2.  2. -1.] acc= 1.0\n",
      "w= [ 2.  2. -1.] acc= 1.0\n"
     ]
    }
   ],
   "source": [
    "print('y=', Y)\n",
    "for _ in range(5):\n",
    "    h = train(X, Y, W)\n",
    "    print('w=', W, 'acc=', np.mean(h == Y))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## plot"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "    <div class=\"bk-root\">\n",
       "        <a href=\"http://bokeh.pydata.org\" target=\"_blank\" class=\"bk-logo bk-logo-small bk-logo-notebook\"></a>\n",
       "        <span id=\"2160c5cf-de49-4299-a4aa-5510f6f6883a\">Loading BokehJS ...</span>\n",
       "    </div>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "\n",
       "(function(global) {\n",
       "  function now() {\n",
       "    return new Date();\n",
       "  }\n",
       "\n",
       "  var force = true;\n",
       "\n",
       "  if (typeof (window._bokeh_onload_callbacks) === \"undefined\" || force === true) {\n",
       "    window._bokeh_onload_callbacks = [];\n",
       "    window._bokeh_is_loading = undefined;\n",
       "  }\n",
       "\n",
       "\n",
       "  \n",
       "  if (typeof (window._bokeh_timeout) === \"undefined\" || force === true) {\n",
       "    window._bokeh_timeout = Date.now() + 5000;\n",
       "    window._bokeh_failed_load = false;\n",
       "  }\n",
       "\n",
       "  var NB_LOAD_WARNING = {'data': {'text/html':\n",
       "     \"<div style='background-color: #fdd'>\\n\"+\n",
       "     \"<p>\\n\"+\n",
       "     \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n",
       "     \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n",
       "     \"</p>\\n\"+\n",
       "     \"<ul>\\n\"+\n",
       "     \"<li>re-rerun `output_notebook()` to attempt to load from CDN again, or</li>\\n\"+\n",
       "     \"<li>use INLINE resources instead, as so:</li>\\n\"+\n",
       "     \"</ul>\\n\"+\n",
       "     \"<code>\\n\"+\n",
       "     \"from bokeh.resources import INLINE\\n\"+\n",
       "     \"output_notebook(resources=INLINE)\\n\"+\n",
       "     \"</code>\\n\"+\n",
       "     \"</div>\"}};\n",
       "\n",
       "  function display_loaded() {\n",
       "    if (window.Bokeh !== undefined) {\n",
       "      document.getElementById(\"2160c5cf-de49-4299-a4aa-5510f6f6883a\").textContent = \"BokehJS successfully loaded.\";\n",
       "    } else if (Date.now() < window._bokeh_timeout) {\n",
       "      setTimeout(display_loaded, 100)\n",
       "    }\n",
       "  }\n",
       "\n",
       "  function run_callbacks() {\n",
       "    window._bokeh_onload_callbacks.forEach(function(callback) { callback() });\n",
       "    delete window._bokeh_onload_callbacks\n",
       "    console.info(\"Bokeh: all callbacks have finished\");\n",
       "  }\n",
       "\n",
       "  function load_libs(js_urls, callback) {\n",
       "    window._bokeh_onload_callbacks.push(callback);\n",
       "    if (window._bokeh_is_loading > 0) {\n",
       "      console.log(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n",
       "      return null;\n",
       "    }\n",
       "    if (js_urls == null || js_urls.length === 0) {\n",
       "      run_callbacks();\n",
       "      return null;\n",
       "    }\n",
       "    console.log(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n",
       "    window._bokeh_is_loading = js_urls.length;\n",
       "    for (var i = 0; i < js_urls.length; i++) {\n",
       "      var url = js_urls[i];\n",
       "      var s = document.createElement('script');\n",
       "      s.src = url;\n",
       "      s.async = false;\n",
       "      s.onreadystatechange = s.onload = function() {\n",
       "        window._bokeh_is_loading--;\n",
       "        if (window._bokeh_is_loading === 0) {\n",
       "          console.log(\"Bokeh: all BokehJS libraries loaded\");\n",
       "          run_callbacks()\n",
       "        }\n",
       "      };\n",
       "      s.onerror = function() {\n",
       "        console.warn(\"failed to load library \" + url);\n",
       "      };\n",
       "      console.log(\"Bokeh: injecting script tag for BokehJS library: \", url);\n",
       "      document.getElementsByTagName(\"head\")[0].appendChild(s);\n",
       "    }\n",
       "  };var element = document.getElementById(\"2160c5cf-de49-4299-a4aa-5510f6f6883a\");\n",
       "  if (element == null) {\n",
       "    console.log(\"Bokeh: ERROR: autoload.js configured with elementid '2160c5cf-de49-4299-a4aa-5510f6f6883a' but no matching script tag was found. \")\n",
       "    return false;\n",
       "  }\n",
       "\n",
       "  var js_urls = [\"https://cdn.pydata.org/bokeh/release/bokeh-0.12.4.min.js\", \"https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.4.min.js\"];\n",
       "\n",
       "  var inline_js = [\n",
       "    function(Bokeh) {\n",
       "      Bokeh.set_log_level(\"info\");\n",
       "    },\n",
       "    \n",
       "    function(Bokeh) {\n",
       "      \n",
       "      document.getElementById(\"2160c5cf-de49-4299-a4aa-5510f6f6883a\").textContent = \"BokehJS is loading...\";\n",
       "    },\n",
       "    function(Bokeh) {\n",
       "      console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-0.12.4.min.css\");\n",
       "      Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-0.12.4.min.css\");\n",
       "      console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.4.min.css\");\n",
       "      Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.4.min.css\");\n",
       "    }\n",
       "  ];\n",
       "\n",
       "  function run_inline_js() {\n",
       "    \n",
       "    if ((window.Bokeh !== undefined) || (force === true)) {\n",
       "      for (var i = 0; i < inline_js.length; i++) {\n",
       "        inline_js[i](window.Bokeh);\n",
       "      }if (force === true) {\n",
       "        display_loaded();\n",
       "      }} else if (Date.now() < window._bokeh_timeout) {\n",
       "      setTimeout(run_inline_js, 100);\n",
       "    } else if (!window._bokeh_failed_load) {\n",
       "      console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n",
       "      window._bokeh_failed_load = true;\n",
       "    } else if (force !== true) {\n",
       "      var cell = $(document.getElementById(\"2160c5cf-de49-4299-a4aa-5510f6f6883a\")).parents('.cell').data().cell;\n",
       "      cell.output_area.append_execute_result(NB_LOAD_WARNING)\n",
       "    }\n",
       "\n",
       "  }\n",
       "\n",
       "  if (window._bokeh_is_loading === 0) {\n",
       "    console.log(\"Bokeh: BokehJS loaded, going straight to plotting\");\n",
       "    run_inline_js();\n",
       "  } else {\n",
       "    load_libs(js_urls, function() {\n",
       "      console.log(\"Bokeh: BokehJS plotting callback run at\", now());\n",
       "      run_inline_js();\n",
       "    });\n",
       "  }\n",
       "}(this));"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "    <div class=\"bk-root\">\n",
       "        <div class=\"bk-plotdiv\" id=\"72eb47c3-6534-48a0-96d9-e185ca72086f\"></div>\n",
       "    </div>\n",
       "<script type=\"text/javascript\">\n",
       "  \n",
       "  (function(global) {\n",
       "    function now() {\n",
       "      return new Date();\n",
       "    }\n",
       "  \n",
       "    var force = false;\n",
       "  \n",
       "    if (typeof (window._bokeh_onload_callbacks) === \"undefined\" || force === true) {\n",
       "      window._bokeh_onload_callbacks = [];\n",
       "      window._bokeh_is_loading = undefined;\n",
       "    }\n",
       "  \n",
       "  \n",
       "    \n",
       "    if (typeof (window._bokeh_timeout) === \"undefined\" || force === true) {\n",
       "      window._bokeh_timeout = Date.now() + 0;\n",
       "      window._bokeh_failed_load = false;\n",
       "    }\n",
       "  \n",
       "    var NB_LOAD_WARNING = {'data': {'text/html':\n",
       "       \"<div style='background-color: #fdd'>\\n\"+\n",
       "       \"<p>\\n\"+\n",
       "       \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n",
       "       \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n",
       "       \"</p>\\n\"+\n",
       "       \"<ul>\\n\"+\n",
       "       \"<li>re-rerun `output_notebook()` to attempt to load from CDN again, or</li>\\n\"+\n",
       "       \"<li>use INLINE resources instead, as so:</li>\\n\"+\n",
       "       \"</ul>\\n\"+\n",
       "       \"<code>\\n\"+\n",
       "       \"from bokeh.resources import INLINE\\n\"+\n",
       "       \"output_notebook(resources=INLINE)\\n\"+\n",
       "       \"</code>\\n\"+\n",
       "       \"</div>\"}};\n",
       "  \n",
       "    function display_loaded() {\n",
       "      if (window.Bokeh !== undefined) {\n",
       "        document.getElementById(\"72eb47c3-6534-48a0-96d9-e185ca72086f\").textContent = \"BokehJS successfully loaded.\";\n",
       "      } else if (Date.now() < window._bokeh_timeout) {\n",
       "        setTimeout(display_loaded, 100)\n",
       "      }\n",
       "    }\n",
       "  \n",
       "    function run_callbacks() {\n",
       "      window._bokeh_onload_callbacks.forEach(function(callback) { callback() });\n",
       "      delete window._bokeh_onload_callbacks\n",
       "      console.info(\"Bokeh: all callbacks have finished\");\n",
       "    }\n",
       "  \n",
       "    function load_libs(js_urls, callback) {\n",
       "      window._bokeh_onload_callbacks.push(callback);\n",
       "      if (window._bokeh_is_loading > 0) {\n",
       "        console.log(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n",
       "        return null;\n",
       "      }\n",
       "      if (js_urls == null || js_urls.length === 0) {\n",
       "        run_callbacks();\n",
       "        return null;\n",
       "      }\n",
       "      console.log(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n",
       "      window._bokeh_is_loading = js_urls.length;\n",
       "      for (var i = 0; i < js_urls.length; i++) {\n",
       "        var url = js_urls[i];\n",
       "        var s = document.createElement('script');\n",
       "        s.src = url;\n",
       "        s.async = false;\n",
       "        s.onreadystatechange = s.onload = function() {\n",
       "          window._bokeh_is_loading--;\n",
       "          if (window._bokeh_is_loading === 0) {\n",
       "            console.log(\"Bokeh: all BokehJS libraries loaded\");\n",
       "            run_callbacks()\n",
       "          }\n",
       "        };\n",
       "        s.onerror = function() {\n",
       "          console.warn(\"failed to load library \" + url);\n",
       "        };\n",
       "        console.log(\"Bokeh: injecting script tag for BokehJS library: \", url);\n",
       "        document.getElementsByTagName(\"head\")[0].appendChild(s);\n",
       "      }\n",
       "    };var element = document.getElementById(\"72eb47c3-6534-48a0-96d9-e185ca72086f\");\n",
       "    if (element == null) {\n",
       "      console.log(\"Bokeh: ERROR: autoload.js configured with elementid '72eb47c3-6534-48a0-96d9-e185ca72086f' but no matching script tag was found. \")\n",
       "      return false;\n",
       "    }\n",
       "  \n",
       "    var js_urls = [];\n",
       "  \n",
       "    var inline_js = [\n",
       "      function(Bokeh) {\n",
       "        (function() {\n",
       "          var fn = function() {\n",
       "            var docs_json = {\"9d8a46b9-464e-467e-8996-17316866b842\":{\"roots\":{\"references\":[{\"attributes\":{\"formatter\":{\"id\":\"a4d17122-bcc4-4028-932d-e014c4aa0de8\",\"type\":\"BasicTickFormatter\"},\"plot\":{\"id\":\"efa79ece-28e4-4d70-ae70-4ac2c2793ec7\",\"subtype\":\"Figure\",\"type\":\"Plot\"},\"ticker\":{\"id\":\"613070b0-b76a-4c08-832f-3a9b5ee2a2f8\",\"type\":\"BasicTicker\"}},\"id\":\"6257cf02-c549-4bde-8a81-798646453130\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"613070b0-b76a-4c08-832f-3a9b5ee2a2f8\",\"type\":\"BasicTicker\"},{\"attributes\":{\"fill_color\":{\"field\":\"fill_color\"},\"line_color\":{\"field\":\"line_color\"},\"size\":{\"units\":\"screen\",\"value\":10},\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"2adfe167-9c80-4ae9-8b39-a0eca2da3e83\",\"type\":\"Circle\"},{\"attributes\":{\"dimension\":1,\"plot\":{\"id\":\"efa79ece-28e4-4d70-ae70-4ac2c2793ec7\",\"subtype\":\"Figure\",\"type\":\"Plot\"},\"ticker\":{\"id\":\"613070b0-b76a-4c08-832f-3a9b5ee2a2f8\",\"type\":\"BasicTicker\"}},\"id\":\"112d1507-521f-4284-8be3-2cb23deeca76\",\"type\":\"Grid\"},{\"attributes\":{\"plot\":{\"id\":\"efa79ece-28e4-4d70-ae70-4ac2c2793ec7\",\"subtype\":\"Figure\",\"type\":\"Plot\"}},\"id\":\"8fe01a96-eaa6-4007-8219-cfff7f9b3abf\",\"type\":\"PanTool\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":{\"value\":0.5},\"fill_color\":{\"value\":\"lightgrey\"},\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":{\"value\":1.0},\"line_color\":{\"value\":\"black\"},\"line_dash\":[4,4],\"line_width\":{\"value\":2},\"plot\":null,\"render_mode\":\"css\",\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"585025b1-845e-4a6d-af47-fd033c62905a\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"data_source\":{\"id\":\"26d97b99-35f3-48b3-99e9-019cd0ef2f45\",\"type\":\"ColumnDataSource\"},\"glyph\":{\"id\":\"ae747e30-2abf-4416-9077-bb3c1987293a\",\"type\":\"Line\"},\"hover_glyph\":null,\"nonselection_glyph\":{\"id\":\"83b32469-0c6c-47b4-b463-bbcb081ac382\",\"type\":\"Line\"},\"selection_glyph\":null},\"id\":\"b207ac70-511b-4be9-a70e-e76a91766dd6\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"plot\":{\"id\":\"efa79ece-28e4-4d70-ae70-4ac2c2793ec7\",\"subtype\":\"Figure\",\"type\":\"Plot\"}},\"id\":\"d4926bb9-5f28-4356-9188-848147a63c34\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"overlay\":{\"id\":\"585025b1-845e-4a6d-af47-fd033c62905a\",\"type\":\"BoxAnnotation\"},\"plot\":{\"id\":\"efa79ece-28e4-4d70-ae70-4ac2c2793ec7\",\"subtype\":\"Figure\",\"type\":\"Plot\"}},\"id\":\"b614bea6-fdb2-4569-b3af-046489ad31a7\",\"type\":\"BoxZoomTool\"},{\"attributes\":{},\"id\":\"20c8bfc6-71b4-4ace-b412-2ad08ed23966\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"plot\":{\"id\":\"efa79ece-28e4-4d70-ae70-4ac2c2793ec7\",\"subtype\":\"Figure\",\"type\":\"Plot\"}},\"id\":\"53727b7d-2353-4473-9d74-120cf3db7d2a\",\"type\":\"SaveTool\"},{\"attributes\":{\"plot\":{\"id\":\"efa79ece-28e4-4d70-ae70-4ac2c2793ec7\",\"subtype\":\"Figure\",\"type\":\"Plot\"}},\"id\":\"e8da8fc4-101f-484a-9a28-6f237df8760c\",\"type\":\"ResetTool\"},{\"attributes\":{\"line_color\":{\"value\":\"#1f77b4\"},\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"ae747e30-2abf-4416-9077-bb3c1987293a\",\"type\":\"Line\"},{\"attributes\":{\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#1f77b4\"},\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"83b32469-0c6c-47b4-b463-bbcb081ac382\",\"type\":\"Line\"},{\"attributes\":{\"data_source\":{\"id\":\"24796f9f-0d5c-4942-88b9-7d33c750dcc2\",\"type\":\"ColumnDataSource\"},\"glyph\":{\"id\":\"2adfe167-9c80-4ae9-8b39-a0eca2da3e83\",\"type\":\"Circle\"},\"hover_glyph\":null,\"nonselection_glyph\":{\"id\":\"70849fec-7b3f-40fb-8f91-1b175f2dcf6e\",\"type\":\"Circle\"},\"selection_glyph\":null},\"id\":\"80b7f1a6-29a2-4322-89a1-34f1b5914e54\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"callback\":null,\"column_names\":[\"x\",\"y\"],\"data\":{\"x\":[-1.5,1.5],\"y\":[2.0,-1.0]}},\"id\":\"26d97b99-35f3-48b3-99e9-019cd0ef2f45\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"plot\":null,\"text\":\"\"},\"id\":\"1d49710a-9e56-4e6c-8d74-54a526d6b617\",\"type\":\"Title\"},{\"attributes\":{\"callback\":null},\"id\":\"15aa450c-dc5f-4725-8085-3e1241143829\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"a4d17122-bcc4-4028-932d-e014c4aa0de8\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"callback\":null,\"column_names\":[\"x\",\"y\",\"fill_color\",\"line_color\"],\"data\":{\"fill_color\":[\"green\",\"green\",\"green\",\"red\",\"red\"],\"line_color\":[\"green\",\"green\",\"green\",\"red\",\"red\"],\"x\":[0,1,1,-1,1],\"y\":[1,0,1,1,-1]}},\"id\":\"24796f9f-0d5c-4942-88b9-7d33c750dcc2\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"plot\":{\"id\":\"efa79ece-28e4-4d70-ae70-4ac2c2793ec7\",\"subtype\":\"Figure\",\"type\":\"Plot\"}},\"id\":\"0b1ef167-1944-4ba8-9ddd-2441a23ce4f6\",\"type\":\"HelpTool\"},{\"attributes\":{\"below\":[{\"id\":\"bd1f2a2e-466f-46ca-bf88-ae6166a81a4c\",\"type\":\"LinearAxis\"}],\"left\":[{\"id\":\"6257cf02-c549-4bde-8a81-798646453130\",\"type\":\"LinearAxis\"}],\"renderers\":[{\"id\":\"bd1f2a2e-466f-46ca-bf88-ae6166a81a4c\",\"type\":\"LinearAxis\"},{\"id\":\"53f8b72e-050a-4bb6-b3f4-f7675eb6ca10\",\"type\":\"Grid\"},{\"id\":\"6257cf02-c549-4bde-8a81-798646453130\",\"type\":\"LinearAxis\"},{\"id\":\"112d1507-521f-4284-8be3-2cb23deeca76\",\"type\":\"Grid\"},{\"id\":\"585025b1-845e-4a6d-af47-fd033c62905a\",\"type\":\"BoxAnnotation\"},{\"id\":\"80b7f1a6-29a2-4322-89a1-34f1b5914e54\",\"type\":\"GlyphRenderer\"},{\"id\":\"b207ac70-511b-4be9-a70e-e76a91766dd6\",\"type\":\"GlyphRenderer\"}],\"title\":{\"id\":\"1d49710a-9e56-4e6c-8d74-54a526d6b617\",\"type\":\"Title\"},\"tool_events\":{\"id\":\"92255fb0-2b58-4bb8-a9b8-072a11214d69\",\"type\":\"ToolEvents\"},\"toolbar\":{\"id\":\"6e317923-97cd-4c37-a8b1-a9240a45fb73\",\"type\":\"Toolbar\"},\"x_range\":{\"id\":\"15aa450c-dc5f-4725-8085-3e1241143829\",\"type\":\"DataRange1d\"},\"y_range\":{\"id\":\"d124dd27-1723-455c-9839-3ef285c33ce1\",\"type\":\"DataRange1d\"}},\"id\":\"efa79ece-28e4-4d70-ae70-4ac2c2793ec7\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{},\"id\":\"92255fb0-2b58-4bb8-a9b8-072a11214d69\",\"type\":\"ToolEvents\"},{\"attributes\":{},\"id\":\"c30ac0fc-6fc6-4e00-9a8e-e4635cde2cd1\",\"type\":\"BasicTicker\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#1f77b4\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#1f77b4\"},\"size\":{\"units\":\"screen\",\"value\":10},\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"70849fec-7b3f-40fb-8f91-1b175f2dcf6e\",\"type\":\"Circle\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"8fe01a96-eaa6-4007-8219-cfff7f9b3abf\",\"type\":\"PanTool\"},{\"id\":\"d4926bb9-5f28-4356-9188-848147a63c34\",\"type\":\"WheelZoomTool\"},{\"id\":\"b614bea6-fdb2-4569-b3af-046489ad31a7\",\"type\":\"BoxZoomTool\"},{\"id\":\"53727b7d-2353-4473-9d74-120cf3db7d2a\",\"type\":\"SaveTool\"},{\"id\":\"e8da8fc4-101f-484a-9a28-6f237df8760c\",\"type\":\"ResetTool\"},{\"id\":\"0b1ef167-1944-4ba8-9ddd-2441a23ce4f6\",\"type\":\"HelpTool\"}]},\"id\":\"6e317923-97cd-4c37-a8b1-a9240a45fb73\",\"type\":\"Toolbar\"},{\"attributes\":{\"callback\":null},\"id\":\"d124dd27-1723-455c-9839-3ef285c33ce1\",\"type\":\"DataRange1d\"},{\"attributes\":{\"formatter\":{\"id\":\"20c8bfc6-71b4-4ace-b412-2ad08ed23966\",\"type\":\"BasicTickFormatter\"},\"plot\":{\"id\":\"efa79ece-28e4-4d70-ae70-4ac2c2793ec7\",\"subtype\":\"Figure\",\"type\":\"Plot\"},\"ticker\":{\"id\":\"c30ac0fc-6fc6-4e00-9a8e-e4635cde2cd1\",\"type\":\"BasicTicker\"}},\"id\":\"bd1f2a2e-466f-46ca-bf88-ae6166a81a4c\",\"type\":\"LinearAxis\"},{\"attributes\":{\"plot\":{\"id\":\"efa79ece-28e4-4d70-ae70-4ac2c2793ec7\",\"subtype\":\"Figure\",\"type\":\"Plot\"},\"ticker\":{\"id\":\"c30ac0fc-6fc6-4e00-9a8e-e4635cde2cd1\",\"type\":\"BasicTicker\"}},\"id\":\"53f8b72e-050a-4bb6-b3f4-f7675eb6ca10\",\"type\":\"Grid\"}],\"root_ids\":[\"efa79ece-28e4-4d70-ae70-4ac2c2793ec7\"]},\"title\":\"Bokeh Application\",\"version\":\"0.12.4\"}};\n",
       "            var render_items = [{\"docid\":\"9d8a46b9-464e-467e-8996-17316866b842\",\"elementid\":\"72eb47c3-6534-48a0-96d9-e185ca72086f\",\"modelid\":\"efa79ece-28e4-4d70-ae70-4ac2c2793ec7\"}];\n",
       "            \n",
       "            Bokeh.embed.embed_items(docs_json, render_items);\n",
       "          };\n",
       "          if (document.readyState != \"loading\") fn();\n",
       "          else document.addEventListener(\"DOMContentLoaded\", fn);\n",
       "        })();\n",
       "      },\n",
       "      function(Bokeh) {\n",
       "      }\n",
       "    ];\n",
       "  \n",
       "    function run_inline_js() {\n",
       "      \n",
       "      if ((window.Bokeh !== undefined) || (force === true)) {\n",
       "        for (var i = 0; i < inline_js.length; i++) {\n",
       "          inline_js[i](window.Bokeh);\n",
       "        }if (force === true) {\n",
       "          display_loaded();\n",
       "        }} else if (Date.now() < window._bokeh_timeout) {\n",
       "        setTimeout(run_inline_js, 100);\n",
       "      } else if (!window._bokeh_failed_load) {\n",
       "        console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n",
       "        window._bokeh_failed_load = true;\n",
       "      } else if (force !== true) {\n",
       "        var cell = $(document.getElementById(\"72eb47c3-6534-48a0-96d9-e185ca72086f\")).parents('.cell').data().cell;\n",
       "        cell.output_area.append_execute_result(NB_LOAD_WARNING)\n",
       "      }\n",
       "  \n",
       "    }\n",
       "  \n",
       "    if (window._bokeh_is_loading === 0) {\n",
       "      console.log(\"Bokeh: BokehJS loaded, going straight to plotting\");\n",
       "      run_inline_js();\n",
       "    } else {\n",
       "      load_libs(js_urls, function() {\n",
       "        console.log(\"Bokeh: BokehJS plotting callback run at\", now());\n",
       "        run_inline_js();\n",
       "      });\n",
       "    }\n",
       "  }(this));\n",
       "</script>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "output_notebook()\n",
    "\n",
    "color = list(map({0: 'red', 1: 'green'}.__getitem__, Y))\n",
    "x0, y0 = -1.5, (-1.5 * -W[0] - W[2]) / W[1]\n",
    "x1, y1 = 1.5, (1.5 * -W[0] - W[2]) / W[1]\n",
    "\n",
    "plot = figure()\n",
    "plot.circle(x=X[:, 0], y=X[:, 1], color=color, size=10)\n",
    "plot.line(x=[x0, x1], y=[y0, y1])\n",
    "show(plot)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
